package com.wq.sofa.framework.rpc.boot;

import com.wq.sofa.framework.rpc.boot.factory.ImportRpcService;
import com.wq.sofa.framework.service.common.HelloExampleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @Author: wangqiang20995
 * @Date:2018/10/15
 * @Description:使手动使用sofa-api暴露和引用服务
 * @Resource:
 */
@Component
@SpringBootApplication
public class SofaRpcBootDemoServerWithAPIApplication {

    @Autowired
    private ImportRpcService importRpcService;

    private Logger logger = LoggerFactory.getLogger(getClass());

    public static void main(String args[]){
        SpringApplication springApplication = new SpringApplication(SofaRpcBootDemoServerWithAPIApplication.class);

        ApplicationContext applicationContext = springApplication.run(args);

        SofaRpcBootDemoServerWithAPIApplication apiApplication = applicationContext.getBean(SofaRpcBootDemoServerWithAPIApplication.class);
        apiApplication.callRpcService();

    }

    private void callRpcService(){
        logger.info("call rpc service");
        HelloExampleService rpcService = importRpcService.importService(HelloExampleService.class);
        System.out.println(rpcService.saySync("sofa api client"));
    }
}
